home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / game / board / Crafty-15.19.lha / crafty-15.19 / src / X86.s < prev   
Text File  |  1998-09-13  |  19KB  |  585 lines

  1. alignment = 4
  2.  
  3.         .text
  4.         .align  alignment, 0x90
  5.         .globl  _PopCnt
  6. _PopCnt:
  7.         movl    4(%esp), %eax
  8.         movl    8(%esp), %edx
  9.         pushl   %ebx
  10.         pushl   %esi
  11. # x = (x >> 1  & 0x55555555) + (x & 0x55555555);
  12.         movl    $0x55555555, %esi
  13.         movl    %eax, %ecx
  14.         shrl    $1, %eax
  15.         movl    %edx, %ebx
  16.         shrl    $1, %edx
  17.         andl    %esi, %ecx
  18.         andl    %esi, %ebx
  19.         andl    %esi, %eax
  20.         andl    %esi, %edx
  21.         addl    %ecx, %eax
  22.         addl    %ebx, %edx
  23. # x = ((x >> 2) & 0x33333333) + (x & 0x33333333);
  24.         movl    $0x33333333, %esi
  25.         movl    %eax, %ecx
  26.         shrl    $2, %eax
  27.         movl    %edx, %ebx
  28.         shrl    $2, %edx
  29.         andl    %esi, %ecx
  30.         andl    %esi, %ebx
  31.         andl    %esi, %eax
  32.         andl    %esi, %edx
  33.         addl    %ecx, %eax
  34.         addl    %ebx, %edx
  35. # x = ((x >> 4) + x) & 0x0f0f0f0f;
  36.         movl    %eax, %ecx
  37.         shrl    $4, %eax
  38.         movl    %edx, %ebx
  39.         shrl    $4, %edx
  40.         addl    %ecx, %eax
  41.         addl    %ebx, %edx
  42.         andl    $0x0f0f0f0f, %eax
  43.         andl    $0x0f0f0f0f, %edx
  44. # x = ((x >> 8) + x);
  45.         movl    %eax, %ecx
  46.         shrl    $8, %eax
  47.         movl    %edx, %ebx
  48.         shrl    $8, %edx
  49.         addl    %ecx, %eax
  50.         addl    %ebx, %edx
  51. # return (x + (x >> 16)) & 0xff;
  52.         movl    %eax, %ecx
  53.         shrl    $16, %eax
  54.         movl    %edx, %ebx
  55.         shrl    $16, %edx
  56.         addl    %ecx, %eax
  57.         addl    %ebx, %edx
  58.         popl    %esi
  59.         popl    %ebx
  60.         addl    %edx, %eax
  61.         andl    $0x7f, %eax
  62.         ret
  63.  
  64. /*----------------------------------------------------------------------------*/
  65.  
  66.         .align  alignment, 0x90
  67.         .globl  _FirstOne
  68. _FirstOne:
  69.         cmpl    $1, 8(%esp)
  70.         sbbl    %eax, %eax
  71.         movl    $65535, %ecx
  72.         movl    8(%esp,%eax,4), %edx
  73.         andl    $32, %eax
  74.         cmpl    %edx, %ecx
  75.         sbbl    %ecx, %ecx
  76.         andl    $16, %ecx
  77.         shrl    %cl, %edx
  78.         subl    %ecx, %eax
  79.         movl    $255, %ecx
  80.         cmpl    %edx, %ecx
  81.         sbbl    %ecx, %ecx
  82.         andl    $8, %ecx
  83.         shrl    %cl, %edx
  84.         subl    %ecx, %eax
  85.         addl    $24, %eax
  86.         movzbl  _first_ones_8bit(%edx), %ecx
  87.         addl    %ecx, %eax
  88.         ret
  89.  
  90. /*----------------------------------------------------------------------------*/
  91.  
  92.         .align  alignment, 0x90
  93.         .globl  _LastOne
  94. _LastOne:
  95.         cmpl    $1, 4(%esp)
  96.         sbbl    %ecx, %ecx
  97.         movl    %ecx, %eax
  98.         negl    %ecx
  99.         notl    %eax
  100.         andl    $32, %eax
  101.         movl    4(%esp,%ecx,4), %edx
  102.         pushl   %esi
  103.         movl    %edx, %esi
  104.         andl    $0x0000ffff, %esi
  105.         cmpl    $1, %esi
  106.         sbbl    %ecx, %ecx
  107.         andl    $16, %ecx
  108.         shrl    %cl, %edx
  109.         subl    %ecx, %eax
  110.         movl    %edx, %esi
  111.         andl    $0x000000ff, %esi
  112.         cmpl    $1, %esi
  113.         sbbl    %ecx, %ecx
  114.         andl    $8, %ecx
  115.         shrl    %cl, %edx
  116.         subl    %ecx, %eax
  117.         andl    $0x000000ff, %edx
  118.         addl    $24, %eax
  119.         cmpl    $1, %edx
  120.         sbbl    %ecx, %ecx
  121.         popl    %esi
  122.         movzbl  _last_ones_8bit(%edx), %edx
  123.         andl    $56, %ecx
  124.         addl    %edx, %eax
  125.         addl    %ecx, %eax
  126.         ret
  127.  
  128. /*----------------------------------------------------------------------------*/
  129.  
  130.         .align  alignment, 0x90
  131.  
  132. /*----------------------------------------------------------------------------*/
  133.  
  134.         .comm   _first_ones_8bit, 256
  135.         .comm   _last_ones_8bit, 256
  136.  
  137. /*----------------------------------------------------------------------------*/
  138.  
  139. /* Diag info offsets */
  140.     
  141. D_ATTACKS       = 0             # Must be 0 - hard-coded (see comments)
  142. D_MOBILITY      = 4
  143. D_WHICH_ATTACK  = 8
  144. D_SHIFT         = 12
  145. D_MASK          = 13
  146. AD_SHIFT        = 14
  147. AD_MASK         = 15
  148. AD_WHICH_ATTACK = 16
  149. AD_MOBILITY     = 20
  150. AD_ATTACKS      = 24
  151.  
  152. /* Position offsets */
  153.     
  154. W_OCCUPIED       =  0
  155. B_OCCUPIED       =  8
  156. RL90             = 16
  157. RL45             = 24
  158. RR45             = 32
  159.     
  160. /* Struct at offsets:
  161.         struct at {
  162.           unsigned char which_attack[8][64];
  163.           BITBOARD      file_attack_bitboards[8][12];
  164.           unsigned char rank_attack_bitboards[8][12];
  165.           unsigned char length8_mobility[8][12];
  166.           unsigned char short_mobility[116];
  167.         } at;
  168. */
  169.  
  170. WHICH_ATTACK     = 0
  171. FILE_ATTACKS     = 512
  172. RANK_ATTACKS     = 1280
  173. LEN8_MOBILITY    = 1376
  174. SHRT_MOBILITY    = 1472
  175.  
  176.         .text
  177.  
  178. /*
  179.   BITBOARD AttacksDiaga1Func (DIAG_INFO *diag, CHESS_POSITION *board)
  180. */
  181. /*
  182.   #define AttacksDiaga1Int(diagp,boardp)                \
  183.     (diagp)->ad_attacks [               \
  184.       (diagp)->ad_which_attack [            \
  185.     And (SplitShiftr((boardp)->occupied_rl45,   \
  186.              (diagp)->ad_shift),        \
  187.          (diagp)->ad_mask) ] ]
  188. */
  189.         .align  alignment, 0x90
  190.         .globl  _AttacksDiaga1Func
  191. _AttacksDiaga1Func:
  192.         pushl   %esi
  193.         movl    8(%esp), %esi                   /* diag_info     */
  194.         movl    12(%esp), %eax                  /* boardp        */
  195.         movb    AD_SHIFT(%esi), %cl             /* shift         */
  196.         cmpb    $32, %cl
  197.         sbbl    %edx, %edx
  198.         movl    RL45+4(%eax,%edx,4), %eax       /* occupied      */
  199.         movzbl  AD_MASK(%esi), %edx             /* mask          */
  200.         shrl    %cl, %eax
  201.         andl    %edx, %eax
  202.         addl    AD_WHICH_ATTACK(%esi), %eax     /* which_attack  */
  203.         movl    AD_ATTACKS(%esi), %ecx          /* attack_vector */
  204.         movzbl  (%eax), %edx                    /* attack_index  */
  205.         popl    %esi
  206.         movl    (%ecx,%edx,8), %eax
  207.         movl    4(%ecx,%edx,8), %edx
  208.         ret
  209.  
  210. /*
  211.   BITBOARD AttacksDiagh1Func(DIAG_INFO *diag, CHESS_POSITION *board)
  212. */
  213. /*
  214.   #define AttacksDiagh1Int(diagp,boardp)        \
  215.     (diagp)->d_attacks [                \
  216.       (diagp)->d_which_attack [             \
  217.     And (SplitShiftr((boardp)->occupied_rr45,   \
  218.              (diagp)->d_shift),     \
  219.          (diagp)->d_mask) ] ]
  220. */
  221.         .align  alignment, 0x90
  222.         .globl  _AttacksDiagh1Func
  223. _AttacksDiagh1Func:
  224.         pushl   %esi
  225.         movl    8(%esp), %esi                   /* diag_info     */
  226.         movl    12(%esp), %eax                  /* boardp        */
  227.         movb    D_SHIFT(%esi), %cl              /* shift         */
  228.         cmpb    $32, %cl
  229.         sbbl    %edx, %edx
  230.         movl    RR45+4(%eax,%edx,4), %eax       /* occupied      */
  231.         movzbl  D_MASK(%esi), %edx              /* mask          */
  232.         shrl    %cl, %eax
  233.         andl    %edx, %eax
  234.         addl    D_WHICH_ATTACK(%esi), %eax      /* which_attack  */
  235.         movl    (%esi), %ecx                    /* D_ATTACKS     */
  236.                                                 # attack_vector
  237.         movzbl  (%eax), %edx                    /* attack_index  */
  238.         popl    %esi
  239.         movl    (%ecx,%edx,8), %eax
  240.         movl    4(%ecx,%edx,8), %edx
  241.         ret
  242.  
  243. /*
  244.   BITBOARD AttacksBishopFunc(DIAG_INFO *diag, CHESS_POSITION *board)
  245. */
  246. /*
  247.   return Or(AttacksDiaga1Int(diag,board), AttacksDiagh1Int(diag,board));
  248. */
  249.         .align  alignment, 0x90
  250.         .globl  _AttacksBishopFunc
  251. _AttacksBishopFunc:
  252.         pushl   %ebx
  253.         pushl   %esi
  254.         pushl   %edi
  255.         movl    16(%esp), %esi                  /* diag_info     */
  256.         movl    20(%esp), %edi                  /* boardp        */
  257.         movb    AD_SHIFT(%esi), %cl             /* shift         */
  258.         cmpb    $32, %cl
  259.         sbbl    %edx, %edx
  260.         movzbl  AD_MASK(%esi), %ebx             /* mask          */
  261.         movl    RL45+4(%edi,%edx,4), %edi       /* occupied      */
  262.         shrl    %cl, %edi
  263.         andl    %ebx, %edi
  264.         addl    AD_WHICH_ATTACK(%esi), %edi     /* which_attack  */
  265.         movl    AD_ATTACKS(%esi), %ecx          /* attack_vector */
  266.         movzbl  (%edi), %ebx                    /* attack_index  */
  267.         movl    20(%esp), %edi                  /* again boardp  */
  268.         leal    (%ecx,%ebx,8), %edx
  269.         movb    D_SHIFT(%esi), %cl              /* shift         */
  270.         cmp